package com.yuncheng.spcyApi.controller;

import java.util.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import com.yuncheng.spcyApi.alog.annotation.Log;
import com.yuncheng.vo.HttpResult;
import com.yuncheng.common.query.QueryBuilder;
import com.yuncheng.utils.I18nUtil;
import com.yuncheng.common.base.controller.BaseController;
import com.yuncheng.spcyApi.entity.SpcyLog;
import com.yuncheng.spcyApi.service.ISpcyLogService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @Description: 审评查验日志记录
 * @Author: csx
 * @Date: 2023-03-03
 * @Version: V1.0
 */
@Api(tags = "审评查验日志记录接口")
//@RestController
@RequestMapping("/api/spzx-spcy/spcyLog")
public class SpcyLogController extends BaseController<SpcyLog, ISpcyLogService> {

    private static final Logger log = LoggerFactory.getLogger(SpcyLogController.class);

    @Resource
    private ISpcyLogService spcyLogService;

    /**
     * 分页列表查询
     *
     * @param spcyLog
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @Log(title = "审评查验日志记录-分页列表查询")
    @ApiOperation(value = "审评查验日志记录-分页列表查询")
    @GetMapping(value = "/list")
    public HttpResult<?> queryPageList(SpcyLog spcyLog, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
        QueryWrapper<SpcyLog> queryWrapper = QueryBuilder.initQueryWrapper(spcyLog, req.getParameterMap());
        Page<SpcyLog> page = new Page<>(pageNo, pageSize);
        IPage<SpcyLog> pageList = spcyLogService.page(page, queryWrapper);
        for(SpcyLog vo:pageList.getRecords()){
            formatValue(vo);
        }
        return HttpResult.ok(pageList);
    }



    /**
     * 添加
     *
     * @param spcyLog
     * @return
     */
    @Log(title = "审评查验日志记录-添加")
    @ApiOperation(value = "审评查验日志记录-添加")
    //@RequiresPermissions("spcyLog:SpcyLog:add")
    @PostMapping(value = "/add")
    public HttpResult<?> add(@RequestBody SpcyLog spcyLog) {
        HttpResult<String> result = new HttpResult(true);
        spcyLogService.save(spcyLog);
        result.setResult(spcyLog.getId());
        result.setMessage(I18nUtil.message("save.success"));
        return result;
    }

    /**
     * 编辑
     *
     * @param spcyLog
     * @return
     */
    @Log(title = "审评查验日志记录-编辑")
    @ApiOperation(value = "审评查验日志记录-编辑")
    //@RequiresPermissions("spcyLog:SpcyLog:edit")
    @PutMapping(value = "/edit")
    public HttpResult<?> edit(@RequestBody SpcyLog spcyLog) {
        spcyLogService.updateById(spcyLog);
        return HttpResult.ok(I18nUtil.message("update.success"));
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @Log(title = "审评查验日志记录-通过id删除")
    @ApiOperation(value = "审评查验日志记录-通过id删除")
    //@RequiresPermissions("spcyLog:SpcyLog:delete")
    @DeleteMapping(value = "/delete")
    public HttpResult<?> delete(@RequestParam("id") String id) {
        spcyLogService.removeById(id);
        return HttpResult.ok(I18nUtil.message("delete.success"));
    }

    /**
     * 通过id批量删除
     *
     * @param ids
     * @return
     */
    @Log(title = "审评查验日志记录-批量删除")
    @ApiOperation(value = "审评查验日志记录-批量删除")
    //@RequiresPermissions("spcyLog:SpcyLog:delete")
    @DeleteMapping(value = "/deleteBatch")
    public HttpResult<?> deleteBatch(@RequestParam("ids") String ids) {
        spcyLogService.removeByIds(Arrays.asList(ids.split(",")));
        return HttpResult.ok(I18nUtil.message("delete.success"));
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @Log(title = "审评查验日志记录-通过id查询")
    @ApiOperation(value = "审评查验日志记录-通过id查询")
    @GetMapping(value = "/queryById")
    public HttpResult<?> queryById(@RequestParam("id") String id) {
        SpcyLog spcyLog = spcyLogService.getById(id);
        return HttpResult.ok(spcyLog);
    }

    /**
     * 数据转换
     * @param spcyLog
     */
    private void formatValue(SpcyLog spcyLog){
    }
}
